<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>百度地图</title>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=B3f7707c25da5b29a6ff69618788a296"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.js"></script>
    <link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.css" />
    <script type="text/javascript" src="/statics/js/layer/layer.js"></script>
<script type="text/javascript">
	var iscreatr=false;
	function initialize() {

        //---------------------------------------------基础示例---------------------------------------------
        var map = new BMap.Map("allmap",{minZoom:1,maxZoom:20});            // 创建Map实例
        map.centerAndZoom(new BMap.Point(116.4035,39.915),15);  //初始化时，即可设置中心点和地图缩放级别。
        //map.centerAndZoom("成都",15);                     // 初始化地图,设置中心点坐标和地图级别。
        function myFun(result){
            var cityName = result.name;
            map.setCenter(cityName);
            //alert("当前定位城市:"+cityName);
        }
        var myCity = new BMap.LocalCity(); //根据IP定位
        myCity.get(myFun);

		map.enableScrollWheelZoom(true);//鼠标滑动轮子可以滚动
		var geoc = new BMap.Geocoder();   
		map.addEventListener("click", function(e){
			
			var pt = e.point;
			geoc.getLocation(pt, function(rs){

				var addComp = rs.addressComponents;
                parent.$("#f_location").val(addComp.province + "" + addComp.city + "" + addComp.district + "" + addComp.street + "" + addComp.streetNumber) ;
			});    

			if(iscreatr==true)return;
			//---------------------------------------------遮盖物---------------------------------------------
			iscreatr=true;
            parent.$("#zuobiao").val( e.point.lng + ", " + e.point.lat);//打印拖动结束坐标
			 var point = new BMap.Point(e.point.lng ,e.point.lat);//默认
			 // 创建标注对象并添加到地图  
			 var marker = new BMap.Marker(point);  
			 var label = new BMap.Label("可拖动修改定位信息<br />设置完成后关闭本窗口即可",{offset:new BMap.Size(20,-10)});
			 marker.setLabel(label)
			 map.addOverlay(marker);  
			 marker.enableDragging();    //可拖拽
			 marker.addEventListener("dragend", function(e){
                 parent.$("#zuobiao").val( e.point.lng + ", " + e.point.lat);//打印拖动结束坐标
					var pt = e.point;
					geoc.getLocation(pt, function(rs){
						var addComp = rs.addressComponents;
                        parent.$("#f_location").val(addComp.province + "" + addComp.city + "" + addComp.district + "" + addComp.street + "" + addComp.streetNumber) ;
					});    

			 });
		});

	}
 
	function loadScript() {
	   var script = document.createElement("script");
	   script.src = "http://api.map.baidu.com/api?v=1.4&callback=initialize";
	   document.body.appendChild(script);
	}
	//window.onload = loadScript;
    window.onload = initialize;
</script>


</head>
<body>
<div id="allmap" style="width: 700px; height: 500px"></div>
</body>
</html>